#!/usr/bin/ruby
# -*- ruby -*-
#
# http://programmingpraxis.com/2013/04/30/first-unrepeated-character-in-a-string/

require 'pp'

ARGV.each do |str|
  h = {}

  str.length.times do |i|
    ch = str[i, 1]

    h[ch] = [(h[ch] ? h[ch].first : 0 ) + 1, i]
  end

  arr = h.to_a.select { |e| e.last.first == 1 }
  arr.sort! { |a, b| a.last.last <=> b.last.last }

  puts (arr.first || []).first
end
